package cn.lcj.user.controller;

import cn.lcj.basic.dto.LoginInfoDto;
import cn.lcj.basic.exception.BusinessException;
import cn.lcj.basic.utils.AjaxResult;
import cn.lcj.user.service.ILogininfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * $
 *
 * @return $
 * @date $
 * @description $
 */
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILogininfoService logininfoService;
    /**
     * 管理员登录
     *
     * @param
     * @return
     */

    @PostMapping("/account")
    public AjaxResult AccoutLogin(@RequestBody LoginInfoDto loginInfoDto) {

        try {
            //前面是token，后面是对象<String,Object>
            Map<String, Object> map = logininfoService.AccoutLogin(loginInfoDto);
            return new AjaxResult().setObj(map);
        } catch (BusinessException e) {
            return new AjaxResult(false, e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false, "系统繁忙，请稍后再试");
        }
    }
    @PostMapping("/wechat")
    public AjaxResult WechatLogin(@RequestBody Map<String,String>map) {

        try {
           return logininfoService.WechatLogin(map);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false, "系统繁忙，请稍后再试");
        }
    }
    @PostMapping("/wechat/binder")
    public AjaxResult AccoutBinderLogin(@RequestBody Map<String,String>map) {

        try {

            return logininfoService.AccoutBinderLogin(map);
        } catch (BusinessException e) {
            return new AjaxResult(false, e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false, "系统繁忙，请稍后再试");
        }
    }
}